﻿@model SPagedList<Dyd.BaseService.ServiceCenter.Domain.Model.tb_service>
@{
    ViewBag.Title = "服务管理";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var list = XXF.ProjectTool.EnumHelper<XXF.BaseService.ServiceCenter.SystemRuntime.EnumServiceType>.GetAllEnumsOfList2().ToList();
    list = list.Where(s => s.Text != XXF.BaseService.ServiceCenter.SystemRuntime.EnumServiceType.None.ToString()).ToList();
    list.Insert(0, new SelectListItem { Value = int.MinValue.ToString(), Text = "全部" });
}
@Html.AntiForgeryToken()
<div class="main_content">
    <div class="top">
        <h3>@ViewBag.Title</h3>
    </div>
    <div class="box ml10">
        @Html.ActionLink("新增", "ServiceCreate", new { action = "Service" }, new { @class = "btn", id = "addLink" })
    </div>
    <div class="main">
        @using (Ajax.BeginForm("ServiceIndex", "Service", null, new AjaxOptions { UpdateTargetId = "ajaxList", InsertionMode = InsertionMode.Replace }, new { id = "ajaxForm" }))
        {
            <div class="pt10">
                <label>关键字</label>
                <input type="text" name="key" id="key" style="width:350px;" placeholder="服务名称，命名空间，参数，方法，返回类型" maxlength="20" />
                @*<label>服务名称</label>
                    <input type="text" name="servicename" id="servicename" placeholder="服务名称，命名空间" style="width:150px;" maxlength="15" />*@
                <label>服务类型</label>
                @Html.DropDownList("servicetype", list)
                <input type="submit" class="btn" value="搜索" accesskey="S" />
            </div>
        }
    </div>

    <div id="ajaxList" class="m10">
        @Html.Partial("_ServiceIndex", Model)
    </div>
</div>
@section Scripts{
    <script src="~/Scripts/layer/layer.js"></script>
    <link href="~/Scripts/layer/skin/layer.css" rel="stylesheet" />
}

@section footerScripts{
    @Html.SPagerScript()
    <script>
        $(function () {
            $("#ajaxList").on("click", function (event) {
                var type = $(event.target).attr("data-operate");
                switch (type) {
                    case "showItem": showItem(event.target); break;
                    case "editItem": editItem(event.target); break;
                    case "deleteItem": deleteItem(event.target); break;
                    case "showNodeItem": showNodeItem(event.target); break;
                    case "showProtocol": showProtocol(event.target); break;
                    case "showClient": showClient(event.target); break;
                    case "showLog": showLog(event.target); break;
                }
            });
        });

        //编辑
        function editItem(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            var url = "/Service/ServiceEdit/" + id;
            window.location.href = url;
        }

        //查看
        function showItem(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            var url = "/Service/ServiceDetails/" + id;
            window.location.href = url;
        }

        //删除
        function deleteItem(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            if (confirm("确认删除")) {
                $.ajax({
                    url: "/Service/ServiceDelete",
                    type: "post",
                    data: antiToken({ id: id }),
                    dataType: "json",
                    success: function (data) {
                        if (data.Flag) {
                            alert(data.Message);
                            window.location.reload();
                        } else {
                            alert(data.Message);
                        }
                    }
                });
            }
        }

        //查看
        function showNodeItem(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            var url = "/Node/NodeIndex/?serviceid=" + id;
            window.location.href = url;
        }

        //查看协议
        function showProtocol(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            var url = "/Service/ApiDoc?serviceid=" + id;
            window.open(url);
            //var url = "/ProtocolVersion/ProtocolVersionIndex?ServiceId=" + id;
            //layer.open({
            //    type: 2,
            //    title: '',
            //    shadeClose: true,
            //    shade: 0.5,
            //    area: ['90%', '90%'],
            //    content: url //iframe的url
            //});
        }

        //查看协议
        function showClient(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            var url = "/Client/ClientIndex?ServerId=" + id;
            layer.open({
                type: 2,
                title: '',
                shadeClose: true,
                shade: 0.5,
                area: ['90%', '90%'],
                content: url //iframe的url
            });
        }

        //查看协议
        function showLog(obj) {
            var id = $(obj).parent().parent().attr("data-id");
            var url = "/Log/LogIndex?serviceid=" + id;
            window.open(url);
        }

    </script>
}